<?php
namespace Modules\ShopApi\Models;
class ShopProductType extends BaseApiModel
{	
	/**
	 * @name  关联商品图片   一对一
	 */
	 public function image_one()
    {
        return $this->hasOne('Modules\AuthAdmin\Models\AuthImage','id','image_id');
    }
	/**
     * @name  商品一级分类
     */
	public function get_category_one_list(){
		$where = ['level'=>1,'status'=>1,'pid'=>0];
		$data = $this->select('id','title','image_id')
				->with([
					'image_one'=>function($query){
						$query->select('id','url','open');  
					}
				]) 
				->orderBy('sort','asc')
				->orderBy('id','desc')
				->where($where)
				->get()
				->toArray();
		$data = $this->common_image_one($data);		
		return $this->api_success(['data'=>$data]);	
	}
	/**
     * @name  商品二级分类
     */  
	public function get_category_tow_list($pid){
		$where = ['status'=>1,'pid'=>$pid];
		$data = $this->select('id','title','image_id')
				->with([
					'image_one'=>function($query){
						$query->select('id','url','open');  
					}
				]) 
				->orderBy('sort','asc')
				->orderBy('id','desc')
				->where($where)
				->get()
				->toArray();
		$data = $this->common_image_one($data);					
		return $this->api_success(['data'=>$data]);		
	}
}